package com.itheima.chap05;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

/**
 * 需求：键盘录入日期，找出学生列表中生日为指定日期前一天的学生
 */

public class LocalDateDemo {
    static Student[] students = {
            new Student(1 , "小吉" , LocalDate.of(2001,12,31)),
            new Student(2 , "小尼" , LocalDate.of(1986,1,15)),
            new Student(3 , "小泰" , LocalDate.of(2005,12,31)),
            new Student(4 , "小美" , LocalDate.of(1993,5,1)),
            new Student(5 , "小黑" , LocalDate.of(1998,1,15)),
    };

    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        // 1. 键盘录入日期
        System.out.println("请输入日期(2000/01/01)：");
        String dateStr = sc.next();
        // 2.将字符串日期转化为LocalDate对象
        LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy/MM/dd"));
        // 3.计算指定日期的前一天
        LocalDate PreDate = date.minusDays(1);
        // 4.遍历学生列表，找出生日为指定日期前一天的学生
        for (int i = 0; i < students.length; i++) {
            Student s = students[i];
//            if (s.getBirthday().isEqual(PreDate)){
            if (s.getBirthday().getMonthValue() == PreDate.getMonthValue() && s.getBirthday().getDayOfMonth() == PreDate.getDayOfMonth()){
                System.out.println("生日为前一天的学生：" + s.getName());
                return;
            }
        }
        System.out.println("没有找到");
    }
}
